package com.tang.designpattern.singleton;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/4/30 17:54
 * 懒汉式单例
 */
public class SingletonDemo02 {
    //1.私有化构造器
    private SingletonDemo02(){

    }
    //2.类初始化的时候不，调用getInstance方法时，再加载；
    private static SingletonDemo02 instance;
    //3.提供获取该对象的方法，有synchronized,效率低
    public static synchronized SingletonDemo02 getInstance(){
        if(instance==null){
            instance=new SingletonDemo02();
        }
        return instance;
    }
}
